package site.lanmushan.framework.authorization.service;

import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import site.lanmushan.framework.authorization.config.AuthorizationProperties;
import site.lanmushan.framework.authorization.domain.TokenBo;

/**
 * @author Administrator
 */
public abstract class AbstractTokenService implements TokenService {
    @Autowired
    AuthorizationProperties authorizationProperties;

    @Override
    public TokenBo encryptionToken(JSONObject obj, Integer expires) {
        if (expires == null) {
            expires = authorizationProperties.getDuration();
        }
        return encryptionToken(obj, authorizationProperties.getSecretKey(), expires);
    }

    @Override
    public TokenBo encryptionToken(JSONObject obj) {
        return this.encryptionToken(obj, authorizationProperties.getDuration());
    }

    @Override
    public <T> T decryptToken(String token, Class<T> t) {
        return this.decryptToken(token, authorizationProperties.getSecretKey(), t);
    }

    @Override
    public <T> T decryptTokenException(String token, String secretKey, Class<T> t) {
        return null;
    }
}
